<template>
  <div ref="main" style="width:100%;height:360px;margin-bottom:10px" />
</template>

<script>
import * as echarts from 'echarts/core'
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent
} from 'echarts/components'
import { PieChart } from 'echarts/charts'
import { LabelLayout } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'

echarts.use([
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  PieChart,
  CanvasRenderer,
  LabelLayout
])
export default {
  mounted() {
    //  宽度自适应
    window.onresize = () => {
      echarts.init(this.$refs.main).resize()
    }
    const chartDom = this.$refs.main
    const myChart = echarts.init(chartDom)
    let option = {}

    option = {
      title: {
        text: '地区总销售量占比'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 5,
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: [
            { value: 1048, name: '广州' },
            { value: 600, name: '深圳' },
            { value: 600, name: '北京' }
          ]
        }
      ]
    }
    option && myChart.setOption(option)
  }
}
</script>

<style>

</style>
